﻿using DevExpress.XtraGrid.Demos.util;
using DXApplicationTangche.UC.客户CRM.Service;
using DXApplicationTangche.UC.订单一览新.订单预览新.service;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace DXApplicationTangche.UC.坚山上海.坚山上海新
{
    public partial class Form受托加工地址保存 : DevExpress.XtraEditors.XtraForm
    {
        private bool update;
        private OutSourcingReceiverAddressDTO outSourcingReceiverAddressDTO;
        public Form受托加工地址保存()
        {
            InitializeComponent();
            this.update = false;
        }

        public Form受托加工地址保存(OutSourcingReceiverAddressDTO outSourcingReceiverAddressDTO) {
            InitializeComponent();
            this.update = true;
            this.outSourcingReceiverAddressDTO = outSourcingReceiverAddressDTO;
        }

        private void simpleButton添加_Click(object sender, EventArgs e)
        {
            if ((String.IsNullOrWhiteSpace(this.textBox店铺编码.Text.Trim()))
                || (String.IsNullOrWhiteSpace(this.textBox国家编码.Text.Trim()))
                || (String.IsNullOrWhiteSpace(this.textBox店铺名称.Text.Trim())) 
                || (String.IsNullOrWhiteSpace(this.textBox收货人姓名.Text.Trim()))
                || (String.IsNullOrWhiteSpace(this.textBox收货人电话.Text.Trim()))
                || (String.IsNullOrWhiteSpace(this.textBox省.Text.Trim()))
                || (String.IsNullOrWhiteSpace(this.textBox市.Text.Trim()))
                || (String.IsNullOrWhiteSpace(this.textBox区.Text.Trim()))
                || (String.IsNullOrWhiteSpace(this.textBox详细地址.Text.Trim())))
            {
                MessageBox.Show("字段不能为空，请将信息补充完整！");
                return;
            }
            OutSourcingReceiverAddressDTO outSourcingReceiverAddressDTO保存地址 = 
                !update?
                new OutSourcingReceiverAddressDTO(  //  新增
                    this.textBox店铺编码.Text.Trim(),
                    this.textBox国家编码.Text.Trim(),
                    this.textBox店铺名称.Text.Trim(),
                    this.textBox收货人姓名.Text.Trim(),
                    this.textBox收货人电话.Text.Trim(),
                    this.textBox省.Text.Trim(),
                    this.textBox市.Text.Trim(),
                    this.textBox区.Text.Trim(),
                    this.textBox详细地址.Text.Trim()
                ):
                this.outSourcingReceiverAddressDTO.build(
                    this.textBox国家编码.Text.Trim(),
                    this.textBox店铺名称.Text.Trim(),
                    this.textBox收货人姓名.Text.Trim(),
                    this.textBox收货人电话.Text.Trim(),
                    this.textBox省.Text.Trim(),
                    this.textBox市.Text.Trim(),
                    this.textBox区.Text.Trim(),
                    this.textBox详细地址.Text.Trim()
                    );  //  修改

            String re = CRM客户Service.saveOutSourcingReceiverAddress(outSourcingReceiverAddressDTO保存地址);
            PlainMessageResult plainMessageResult保存地址 = FunctionHelper.JsonDeserialization<PlainMessageResult>(re);
            if ("200".Equals(plainMessageResult保存地址.errorCode))
            {
                MessageBox.Show("受托加工地址保存完成");
                this.Close();
            }
            else
            {
                MessageBox.Show(plainMessageResult保存地址.errorMessage);
            }
        }
    }
}
